﻿@page "/DocumentViewer"

@using Demo.Blazor.Services
@using System.Linq;

@inject IDemoReportSource DemoReportSource

<div class="demo-description" id="Template">
    <div class="alert alert-warning" role="alert">
        Important Note: Though <a class="helplink" target="_blank" href="https://www.devexpress.com/subscriptions/reporting/">DevExpress Reports</a> supports Blazor, it is not included in our Blazor component distribution. To use DevExpress Reports within your Blazor application/project or to replicate the functionality described below, you must purchase a DevExpress Subscription (Reporting Subscription, ASP.NET Subscription, DXperience, or Universal). For more information on what’s included in our product subscriptions, please refer to the following <a class="helplink" target="_blank" href="https://www.devexpress.com/buy/net/">product matrix</a>.
    </div>
    <h2><DemoNavLink Link="DocumentViewer" />Reporting – Document Viewer</h2>
    <p>
        This demo illustrates the DevExpress Blazor <a class="helplink" target="_blank" href="https://docs.devexpress.com/XtraReports/DevExpress.Blazor.Reporting.DxDocumentViewer">Document Viewer</a> that allows end users to preview, print, and export documents.
    </p>
</div>

<div class="row dxbs-fl">
    <div class="col-lg-3 col-sm-5 col-6">
        <div class="form-group">
            <div class="col-form-label dxbs-fl-cpt">
                Report Name:
            </div>
            <DxComboBox Data="@ReportList"
                        @bind-Value="@SelectedReportUrl"
                        TextFieldName="Value">
            </DxComboBox>
        </div>
    </div>
</div>

<DxDocumentViewer ReportUrl=@ReportUrl Height="700px" Width="100%">
    <DxDocumentViewerProgressBarSettings Position="@ProgressBarPosition.TopLeft" />
    <DxDocumentViewerTabPanelSettings Width="500" />
</DxDocumentViewer>
<CodeSnippet_DocumentViewer></CodeSnippet_DocumentViewer>

@code {
    string ReportUrl { get; set; }

    KeyValuePair<string, string> selectedReportUrl;
    KeyValuePair<string, string> SelectedReportUrl {
        get => selectedReportUrl;
        set {
            selectedReportUrl = value;
            ReportUrl = selectedReportUrl.Key;
            InvokeAsync(StateHasChanged);
        }
    }

    Dictionary<string, string> ReportList;

    protected override void OnInitialized() {
        ReportList = DemoReportSource.GetReportList();
        SelectedReportUrl = ReportList.First();
    }
}
